package com.ruoyi.tools.util.param;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;

public class DateUtil {
    //年月日 -> 星期几
    public static String calculateWeekday(Date date) {
        // 将 java.util.Date 转换为 java.time.LocalDate
        LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();

        // 计算星期几
        DayOfWeek dayOfWeek = localDate.getDayOfWeek();

        // 格式化为中文星期几
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("E", Locale.CHINA);
        return formatter.format(dayOfWeek);
    }

    public static void main(String[] args) {
        Date date = new Date(); // 假设为当前日期

        String weekday = calculateWeekday(date);
        System.out.println("The given date is: " + weekday);
    }
}

